#!/usr/bin/ruby

# Foung Vang
# Ruby - Excercise 2
# just excercise

# String
x = "CodingDojo"
puts x.length				# output: 10
puts x.class				# output: String
puts x.upcase
puts x.downcase
puts x[2]					# output: d
puts x.include?("dojo") 	# output: false because it's case sensitive
puts x.include?("dojo")		# output: false because it's case sensitive
puts x.include?("Dojo")		# output: true
puts "This word has the word 'Dojo'" if x.include? "Dojo"

x = "john, charles, matt, joe"
y = ""
puts x.split(", ")
puts x.split(", ").to_s
puts "Y is empty" if y.empty?


# Arrays
a = ["Matz", "Guido", "Dojo", "Choi", "John"]
b = [5, 6, 9, 3, 1, 2, 4, 7, 8, 10]
c = ["Dojo", 9]
d = %w{matz guido dojo choi john}

puts a[4]

x = a + b
puts x.to_s

puts b.class
puts b.shuffle.join("-")

puts x = (a + b) - c
puts a.delete("Choi")
puts a
puts a.length
puts a.reverse
puts "Poping..."
puts a.pop
puts "Pushing..."
puts a.push("Mickey")
puts d


# Ranges
x = (1..5)
puts "Class Name: #{x.class}"
puts "It does include 3!" if x.include?(3)
puts "The last number of this range is " + x.last.to_s
puts "The maximum number of this range is " + x.max.to_s
puts "The minimum number of this range is " + x.min.to_s

y= ('a'..'z')
puts y.to_a.shuffle.to_s

# Hash
x = {"first_name" => "Coding", "last_name" => "Dojo"}
puts x["first_name"], x["last_name"]
puts "Your last name is Dojo" if x["last_name"].eql?("Dojo")

y = {:first_name => "Coding", :last_name => "Dojo"}
puts y[:first_name], y[:last_name]
puts "Y is ", y
puts "DELETING :first_name"
y.delete(:first_name)
puts "Y is now", y

if y.has_key?(:first_name)
	puts "Y has a key called :first_name"
else
	puts "Y does not have a key called :first_name"
end

if y.has_value?("Dojo")
	puts "Y has a value called Dojo"
else
	puts "Y does NOT have a value called Dojo"
end

puts "*****************************************************"
# Blocks
def test
	puts "You are in the method"
	yield
	puts "You are again back to the method"
	yield
end
test {puts "You are in the block"}

def test
	yield(5)
	puts "You are in the method test"
	yield(100)
end
test { |i| puts "You are in the block #{i}" }

def square(num)
	puts "num i #{num}"

	x = yield(num)
	puts "x has a value of #{x}" # 25

	y = yield(num)*x
	puts "y has a value of #{y}" # 625
end

square(5) do |i|
	i*i
end